package com.bdyc.service.springImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.bdyc.controller.custom.UserInfoPo;
import com.bdyc.dao.UserInfoMapper;
import com.bdyc.po.UserInfo;
import com.bdyc.service.spring.UserInfoService;
@Service("userInfoService")
public class UserinfoServiceImpl implements UserInfoService {
	@Autowired(required=true)
	@Qualifier("userInfoMapper")
	private UserInfoMapper userInfoMapper;
	//判断客户登录名唯一方法
	public Integer selectName(String name) {
		return userInfoMapper.selectName(name);
	}
	public UserInfoPo login(String name, String pass) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("name", name);
		map.put("pass",pass);
		return userInfoMapper.login(map);
	}
	//注册客户方法
	public void addUserInfo(UserInfo userInfo) {
		userInfoMapper.insert(userInfo);
	}
	public List<UserInfoPo> findUserInfoList(Map<String, Object> map) {
		//设置limit起始索引 (currentPage-1)*pageSize
		Integer currentPage = (Integer)map.get("page");
		Integer pageSize  = (Integer)map.get("rows");
		//封装查询记录数map
		Integer count = userInfoMapper.findUserInfoListCount(map);
		if(count >0){
			Integer index = count/pageSize;
			System.out.println(count%pageSize);
			Integer sum = count%pageSize==0?index:index +1;
			if(currentPage == null || currentPage <= 0){
				currentPage =1;
			}
			if(currentPage > sum ){
				currentPage=sum ;
			}
			map.put("currentPage",  (currentPage-1)*pageSize);
			map.put("pageSize", pageSize);
		}
		return userInfoMapper.findUserInfoList(map);
	}
	public Integer findUserInfoListCount(Map<String, Object> sendMap) {
		return userInfoMapper.findUserInfoListCount(sendMap);
	}

}
